<template>
	<view class="wp">
		<scroll-view class="source_nav" :scroll-x="true">
			<text :class="{active:navIdx===item.id}" v-for="item in cateList" :key="item.id"
				@click="navTap(item.id)">{{item.title}}</text>
		</scroll-view>
		<view class="source_list">
			<view class="source_item" v-for="item in list" :key="item.id">
				<view class="content" :class="current==item.id?'selected':''" @click="open(item.id)">
					<rich-text class="rich_text" :nodes="item.content" space='emsp'></rich-text>
				</view>
				<view class="source_con">
					<text class="time">{{item.addtime}}</text>
					<view class="share" @click="share(item)">一键分享</view>
				</view>
				<navigator v-if="item.thumb.length>0" :url="'/pages/source/detail?item='+ encodeURIComponent(JSON.stringify(item))">
					<view class="source_img">
						<image v-for="items in item.thumb" :src="items" mode="widthFix" role="img"></image>
					</view>
				</navigator>
				<navigator v-if="item.video" :url="'/pages/source/detail?item='+ encodeURIComponent(JSON.stringify(item))">
					<view class="source_img">
						<video :src="item.video" object-fit="cover"></video>
					</view>
				</navigator>
			</view>
		</view>
		<view class="empty_loading">
			<image v-show="isloading" src="../../static/business/loading.gif" mode=""></image>
			<text v-show="isempty">没有更多了~</text>
		</view>
		<share v-show="isShare" :cancelShow="true" @cancelShare="cancelShare" :shareText="shareText" :shareImg="shareImg" :shareVideo="shareVideo" :shareId="shareId"></share>
	</view>
</template>

<script>
	import share from '@/components/share/share'
	export default {
		components: {
			share
		},
		data() {
			return {
				navIdx: 0,
				cateList: [],
				list: [],
				isShare: false,
				shareText: '',
				shareImg: [],
				shareId: '',
				shareVideo: '',
				page: 0,
				isempty: false,
				isloading: false,
				current: 0,
				mybox: '',
			}
		},
		onLoad(){
			this.getCateList();
			
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh(){
			this.page = 0;
			this.list = [];
			this.getList();
		},
		mounted(){
		},
		methods: {
			getList(){
				this.isloading = true;
				this.isempty = false;
				this.page++;
				this.$axios('Index/saleMaterial', 'POST', 'sale', {
					cateid: this.navIdx,
					page: this.page
				}).then(res => {
					this.isloading = false;
					uni.stopPullDownRefresh()
					if (res.data.code == 200) {
						let data = res.data.data.material;
						this.list = [...this.list, ...data];
						this.isempty = data.length <= 0;
					}
				})
			},
			getCateList() {
				this.$axios('Index/saleCate', 'POST', 'sale').then(res => {
					if (res.data.code == 200) {
						this.cateList = res.data.data;
						this.navIdx = this.cateList[0].id;
						this.getList();
					}
				})
			},
			navTap(id){
				this.navIdx = id;
				this.page = 0;
				this.list = [];
				this.getList();
			},
			open(id){
				this.current = id;
			},
			share(item){
				this.shareText = item.content;
				this.shareVideo = item.video;
				this.shareImg = item.thumb;
				this.shareId = item.id;
				this.isShare = true;
			},
			cancelShare(val){
				this.isShare = val;
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #FBF8FE;
		padding-bottom: 100rpx;
	}
	.wp{
		background: #FBF8FE;
		.source_nav {
			width: 100%;
			white-space: nowrap;
			// background: #ff335d;
			background: $bg-color;
			position: fixed;
			top: 0;
			z-index: 999;
			text {
				color: #fff;
				display: inline-block;
				font-size: 30rpx;
				padding: 15rpx 0 25rpx;
				position: relative;
				margin: 0 20rpx;
			}
		
			.active {
				font-weight: bold;
			}
		
			.active::after {
				border-bottom: 2px #fff solid;
				content: '';
				font-weight: bold;
				position: absolute;
				left: 50%;
				bottom: 0;
				transform: translateX(-50%);
				width: 100%;
			}
		}	
		.source_list{
			padding: 70rpx 0 20rpx;
			.source_item{
				background: #fff;
				margin-bottom: 20rpx;
				padding: 20rpx 20rpx;
				// &:first-child{
				// 	.content{
				// 		-webkit-line-clamp: unset;
				// 		overflow: auto;
				// 	}
				// }
				.content{
					font-weight: bolder;
					overflow: hidden;
					text-overflow: ellipsis;
					word-break: break-all;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 3;
					.rich_text{
						word-wrap: break-all;
						white-space: pre-line;
					}
				}
				.selected{
					-webkit-line-clamp: unset;
					overflow: auto;
				}
				.source_con{
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin: 0 0 20rpx;
					.time{
						color: #999;
						font-size: 22rpx;
					}
					.share{
						border: 1rpx solid $bg-color;
						color: $bg-color;
						padding: 0 20rpx;
						font-size: 24rpx;
						line-height: 45rpx;
						border-radius: 45rpx;
					}
				}
				.source_img{
					display: flex;
					flex-wrap: wrap;
					image{
						margin-right: 10rpx;
						margin-bottom: 10rpx;
						max-width: 30%;
						border-radius: 20rpx;
					}
					video{
						border-radius: 20rpx;
					}
				}
			}
		}
		.empty_loading {
			padding-top: 20upx;
			text-align: center;
			color: #0066CC;
		}
		
		.empty_loading image {
			height: 60upx;
			width: 60upx;
		}
	}
</style>
